<div class="layui-form-item">
    <label for="photo" class="layui-form-label">
        <span class="x-red"></span>{$title}
    </label>
    <div class="layui-input-inline">
        <div class="public-img-box">
            <img src="{$url|default='/static/admin/images/img.png'}" id="{$name}_url" style="width: 120px; height: 120px" alt="">
        </div>
        <button type="button" class="layui-btn" id="{$name}">
            <i class="layui-icon">&#xe67c;</i>上传图片
        </button>
        <input type="hidden" name="{$name}" id="{$name}_input" value="{$url}" />
    </div>
    <div class="layui-form-mid layui-word-aux">

    </div>
</div>
<script>
    layui.use(['form','code','upload'], function(){
        form = layui.form;
        var upload = layui.upload;

        form.render();

        var uploadInst = upload.render({
            elem: '#{$name}' //绑定元素
            ,url: '{$Upurl}' //上传接口
            ,accept: 'images' //只允许上传图片
            ,acceptMime: 'image/*' //只筛选图片
            ,before: function(obj){
                layer.load();
            }
            ,done: function(res){
                if(res.code){
                    $("#{$name}_url").attr("src",res.data.url);
                    $("#{$name}_input").val(res.data.url);
                }else{
                    layer.msg(res.msg,{icon:2,time:1000});
                }
                layer.closeAll('loading');
            }
            ,error: function(res){
                //请求异常回调
                layer.closeAll('loading');
            }
        });
    });
</script>